package com.ty.baobao.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ty.baobao.commons.ServiceMessage;
import com.ty.baobao.pojo.Catalog;
import com.ty.baobao.service.CatalogService;

@RestController
public class CalalogController {
	@Autowired
	private CatalogService catalogService;
	
	@PostMapping("/catalog/add")
	public ServiceMessage add(Catalog catalog) {
		try {
			catalogService.add(catalog);
			return ServiceMessage.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return ServiceMessage.error();
		}
	}
	
	@GetMapping("/catalog")
	public ServiceMessage getCatalogsByPid(long pid) {
		try {
			List<Catalog> list = catalogService.getCatalogsByPid(pid);
			return ServiceMessage.ok(list);
		} catch (Exception e) {
			e.printStackTrace();
			return ServiceMessage.error();
		}
		
	}
}
